package com.en.effectiveJava.chapter1;

import java.lang.reflect.Method;

/**
 * Test类的调用测试类
 * Create by EN
 * On 21/05/18 4:34 PM
*/
public class TestCall {

    public static void main(String[] args) {
        Test test = new Test();
        test.setAge(18);
        test.setName("lili");
        test.descripMe();

        /**
         * 内部类的实例方法
         */
        Test.InnerTest innerTest = test.new InnerTest();
        innerTest.setName("li");
        innerTest.call();

        /**
         * 外部类的实例方法
         */
        Test.StaticTest staticTest = new Test.StaticTest();
        staticTest.setSex("girl");
        staticTest.call();

        /**
         * 局部类的实例方法
         *  局部类无法被实例化,但可以通过类反射机制生成类类型，但无法实例化
         */
        try {
            Class c = Class.forName("com.en.effectiveJava.chapter1.Test$1BlockClass");
            System.out.printf("ClassName is %s!\n", c.getName());
            Method method = c.getMethod("sing");
            //代码会报错：java.lang.InstantiationException(实例化错误)
            Object obj = c.newInstance();
            method.invoke(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.printf("She is very %s!\n",FileClass.appearance);

    }

}
